//package com.github.zdg.recyclerview.itemdecoration;
//
//import android.graphics.Canvas;
//import android.graphics.Rect;
//import android.graphics.drawable.Drawable;
//import android.support.v4.view.ViewCompat;
//import android.support.v7.widget.GridLayoutManager;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.support.v7.widget.StaggeredGridLayoutManager;
//import android.util.Log;
//import android.view.View;
//
///**
// * Created by zoudong on 2017/5/29.
// */
//
//public class GridDivierImp implements IDivierDecoration {
//
//    GridLayoutManager layoutManager;
//
//    public GridDivierImp(RecyclerView recyclerView) {
//        this.layoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
//    }
//
//    @Override
//    public boolean isFirstColumn(int orientation, int position, int spanCount, int childCount) {
//        if (orientation == VERTICAL) {
//            return 0 == getSpanSizeLookup().getSpanIndex(position, spanCount);
//        } else {
//            return 0 == getSpanSizeLookup().getSpanGroupIndex(position, spanCount);
//        }
//    }
//
//    @Override
//    public boolean isLastColumn(int orientation, int position, int spanCount, int childCount) {
//        if (orientation == VERTICAL) {
//            return getSpanSizeLookup().getSpanSize(position) == spanCount || getSpanSizeLookup().getSpanIndex(position, spanCount) == spanCount - 1;
//        } else {
//            GridLayoutManager.SpanSizeLookup sizeLookup = getSpanSizeLookup();
//            return sizeLookup.getSpanGroupIndex(position, spanCount) == sizeLookup.getSpanGroupIndex(childCount - 1, spanCount);
//        }
//    }
//
//    @Override
//    public boolean isFirstRow(int orientation, int position, int spanCount, int childCount) {
//        if (orientation == VERTICAL) {
//            return 0 == getSpanSizeLookup().getSpanGroupIndex(position, spanCount);
//        } else {
//            return 0 == getSpanSizeLookup().getSpanIndex(position, spanCount);
//        }
//    }
//
//    @Override
//    public boolean isLastRow(int orientation, int position, int spanCount, int childCount) {
//        if (orientation == VERTICAL) {
//            GridLayoutManager.SpanSizeLookup sizeLookup = getSpanSizeLookup();
//            return sizeLookup.getSpanGroupIndex(position, spanCount) == sizeLookup.getSpanGroupIndex(childCount - 1, spanCount);
//        } else {
//            return getSpanSizeLookup().getSpanSize(position) == spanCount || getSpanSizeLookup().getSpanIndex(position, spanCount) == (spanCount - 1);
//        }
//    }
//
//    @Override
//    public void drawHorizontal(Canvas canvas, RecyclerView parent) {
//
//    }
//
//    @Override
//    public void drawVertical(Canvas canvas, RecyclerView parent) {
//        final int spanCount = getSpanCount(parent);
//        final int left = parent.getPaddingLeft();
//        final int right = parent.getWidth() - parent.getPaddingRight();
//        int itemCount = parent.getAdapter().getItemCount();
//        final int childCount = parent.getChildCount();
//        RecyclerView.LayoutManager manager = parent.getLayoutManager();
//        for (int i = 0; i < childCount; i++) {
//            final View child = parent.getChildAt(i);
//            final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
//            int adapterPosition = params.getViewAdapterPosition();
//            boolean isFirstRow = isFirstRow(adapterPosition, spanCount, itemCount);
//            boolean isLastRow = isLastRow(manager, adapterPosition, spanCount, itemCount);
//            boolean isFirstColumn = isFirstColumn(manager, adapterPosition, spanCount, itemCount);
//            boolean isLastColumn = isLastColumn(manager, adapterPosition, spanCount, itemCount);
//            Log.e("zoudong", "adapterPosition=" + adapterPosition + " isFirstRow=" + isFirstRow + " isLastRow=" + isLastRow + " isFirstColumn=" + isFirstColumn + " isLastColumn=" + isLastColumn);
//            final Drawable divider = getVerticalDivider(parent, adapterPosition);
//            int intrinsicHeight = divider.getIntrinsicHeight();
//            if (edge.isShowEdge(Edge.TOP_EDGE) && isFirstRow) {
//                final int off_top = params.topMargin + Math.round(ViewCompat.getTranslationY(child));
//                divider.setBounds(left, off_top, right, intrinsicHeight);
//                divider.draw(canvas);
//            }
//            if (isLastRow && !edge.isShowEdge(Edge.BUTTOM_EDGE)) {
//                return;
//            }
//            final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
//            final int bottom = top + intrinsicHeight;
//
//            mVerticalDividerOffsets.put(adapterPosition, intrinsicHeight);
////            Log.e("zoudong", "2->left=" + left + "top=" + top + "right=" + right + "bottom=" + bottom);
//            divider.setBounds(left, top, right, bottom);
//            divider.draw(canvas);
//        }
//    }
//
//    @Override
//    public void offsetsVertical(int orientation, Rect outRect, View view, RecyclerView parent) {
//
//    }
//
//    @Override
//    public void offsetsHorizontal(int orientation, Rect outRect, View view, RecyclerView parent) {
//
//    }
//
//    private GridLayoutManager.SpanSizeLookup getSpanSizeLookup() {
//        return layoutManager.getSpanSizeLookup();
//    }
//
//    private int getSpanCount(RecyclerView parent) {
//        RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
//
//        if (layoutManager instanceof GridLayoutManager) {
//            return ((GridLayoutManager) layoutManager).getSpanCount();
//        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
//            return ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
//        } else if (layoutManager instanceof LinearLayoutManager) {
//            return 1;
//        } else {
//            throw new UnsupportedOperationException("the GridDividerItemDecoration can only be used in " +
//                    "the RecyclerView which use a GridLayoutManager or StaggeredGridLayoutManager");
//        }
//    }
//
//
//    @Override
//    public RecyclerView.LayoutManager getLayoutManager() {
//        return null;
//    }
//}
